package cn.edu.cug.cs.gtl.docsrv.dict.dao.imp;

import cn.edu.cug.cs.gtl.docsrv.config.Configuration;
import cn.edu.cug.cs.gtl.docsrv.dict.dao.DictCatalogDao;
import cn.edu.cug.cs.gtl.mybatis.Session;
import cn.edu.cug.cs.gtl.mybatis.mapper.dict.DictCatalog;
import cn.edu.cug.cs.gtl.mybatis.mapper.dict.DictCatalogMapper;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class DictCatalogDaoImpl implements DictCatalogDao {


    @Override
    public List<DictCatalog> getMasterCatalogs() throws Exception {
        Session s = Configuration.getSession();
        DictCatalogMapper mapper = s.getMapper(DictCatalogMapper.class);
        List<DictCatalog> l =   mapper.selectAllOrderByOrder();
        s.close();
        return l;
    }

    @Override
    public List<DictCatalog> getSlaveCatalogs(String slaveDataSource) throws Exception {
        Session s = null;
        if(slaveDataSource==null || slaveDataSource.isEmpty())
            s = Configuration.getMasterSession();
        else{
            s = Configuration.getSlaveSession(slaveDataSource);
        }
        DictCatalogMapper mapper = s.getMapper(DictCatalogMapper.class);
        List<DictCatalog> l=   mapper.selectAllOrderByOrder();
        s.close();
        return l;
    }
}
